/**
 * Created by dywu on 2015/9/24.
 */

angular.module('module.template', [
    'ngStorage'
])

    .config(['$stateProvider', function ($stateProvider) {
        $stateProvider
            .state('set', {
                'abstract': true,
                url: '',
                views: {
                    '': {
                        template: '<div ui-view="topbar"></div>'
                    },
                    'topbar@set': {
                        templateUrl: template_viewurl + "/topbar.html",
                        controller: 'TopbarController',
                        controllerAs: 'vm',
                    },
                }
            })

    }])

    //清除cookie
    .controller('TopbarController', TopbarController);

TopbarController.$inject = ['$localStorage', 'AUTH_EVENTS', '$scope','$state'];


function TopbarController($localStorage, AUTH_EVENTS, $scope,$state) {
    var vm = this;
    vm.signIn = false;
    vm.loginVisible = false;
    vm.registerVisible = false;
    vm.goSigniIn = goSigniIn;//登录按钮
    vm.goRegister = goRegister;//注册
    vm.goOutSign = goOutSign;//退出
    vm.closebtn = closebtn;//关闭登录
    vm.closebtnt=closebtnt;//关闭注册
    vm.gopassword=gopassword;//忘记密码

    $scope.$on(AUTH_EVENTS.loginSuccess, function (ev, error_info) {
        vm.registerVisible = false;
        vm.loginVisible = false;
        vm.signIn = true;
    })
    if ($localStorage.userid) {
        vm.signIn = true;
    }
    function goSigniIn() {
        vm.loginVisible = true;
    }
    function goRegister() {
        vm.registerVisible = true;
    }
    function goOutSign() {
        vm.signIn = false;
        $localStorage.$reset();
    }
    function closebtn() {
        vm.loginVisible = false;
    }
    function closebtnt(){
        vm.registerVisible = false;
    }
    function gopassword(){
        var newurl="http://localhost:63342/dolicious/index.html#!/forgotpwd";
        window.open(newurl);
        //$state.go("set.forgotpwd");
    }
}